<?php
$stupidResponses=Array("a cookie","a fish","balogna","FISHY","donut","applesauce","gagglesnorf","a monkey","the square root of 2","pi","unknown","too complex for this bot","nonexistant","undefined","an apple",$source_nick,"1/0");

$letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers="0123456789";
$lettersAndNumbers=$letters.$numbers;
/*for($i=2;$i<sizeOf($messageA);$i++){
  $paramA[$i-2]=$messageA[$i];
}*/
if(cmd("randint")){
	if (count($msg_args) == 1) {
		$botInt = 1;
		$topInt = 10;
	} else if (count($msg_args) == 2) {
	  $botInt = 1;
	  $topInt = intval($msg_args[1]);
	} else {
	  $botInt = intval($msg_args[1]);
	  $topInt = intval($msg_args[2]);
  }
  if ($topInt < $botInt) {
		$temp = $botInt;
		$botInt = $topInt;
		$topInt = $temp;
	}
  reply(rand($botInt, $topInt));
}

if(cmd("randstr")){
  $randString="";
	if (count($msg_args) == 1) 
  	$strLength=rand(8, 32);
  else
  	$strLength=min(intval($msg_args[1]), 50);
	
  for($i=0;$i<$strLength;$i++)
		$randString .= $letters[rand(0,strlen($letters))];

  reply($randString);
}

if(cmd("random")){
  $randString="";
	if (count($msg_args) == 1) 
  	$strLength=rand(8, 32);
  else
  	$strLength=min(intval($msg_args[1]), 50);
	
  for($i=0;$i<$strLength;$i++)
		$randString .= $lettersAndNumbers[rand(0,strlen($letters))];

  reply($randString);
}

if(cmd("coin")){
  action('flips a coin');
  sleep(1);
  if (rand(0,10)) {
	  $randInt=rand(0,1);
	  if($randInt)
	    reply("It's heads!");
	  else
	    reply("It's tails!");
	} else {
	  reply("It landed on its side! D:");
	}
}

if(cmd("flip")){
	if (count($msg_args) == 1) 
  	$object = 'a coin';
  else
  	$object = $msg_params;
  	
  action('flips ' . $object);
  sleep(1);
  if (rand(0,10)) {
	  $randInt=rand(0,1);
	  if($randInt)
	    reply("It's heads!");
	  else
	    reply("It's tails!");
	} else {
	  reply("It landed on its side! D:");
	}
}

if(cmd("dice")){
	if (count($msg_args) == 1) {
		$sides = 6;
		$fakesides = 6;
	} else {
	  $sides = max(min(intval($msg_args[1]), 100), 2);
		$fakesides = $msg_args[1];
	  if ((string)$msg_args[1] != $sides)
	  	$sides = -1;
  }
  action("rolls a {$fakesides}-sided die");
  sleep(1);
  if ($sides < 0) {
    reply($stupidResponses[rand(0,sizeOf($stupidResponses)-1)]);
	} else {
  	reply('The answer is ' . rand(1, $sides) . '!');
	}
}

if(cmd("reverse")) reply(strrev($msg_params));
?>